package cn.cvs.servlet;

import cn.cvs.dao.PowerBatteryMapper;
import cn.cvs.pojo.PowerBattery;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet (urlPatterns = "/SelectList")
public class SelectList extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        PowerBatteryMapper powerBatteryMapper =sqlSession.getMapper(PowerBatteryMapper.class);
        int id = Integer.parseInt(req.getParameter("id"));
        try {
            PowerBattery powerBattery =powerBatteryMapper.select(id);
            req.getSession().setAttribute("powerBattery",powerBattery);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
        req.getRequestDispatcher("powrUpdate.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
